package top.dancun.easbaseinfo.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.dancun.common.utils.DataUtils;
import top.dancun.common.utils.PageUtils;
import top.dancun.common.utils.R;
import top.dancun.easbaseinfo.entity.MajorEntity;
import top.dancun.easbaseinfo.service.MajorService;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


//TODO 后续查询院长/等等
/**
 * 
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-09-17 16:31:57
 */
@RestController
@RequestMapping("/major")
public class MajorController extends AbstractController{
    @Autowired
    private MajorService majorService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("easbaseinfo:major:list")
    public R list(@RequestBody Map<String, Object> params){
        PageUtils page = majorService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/listnopage")
    @RequiresPermissions("easbaseinfo:major:list")
    public R listNoPage(@RequestBody Map<String, Object> params){

        Map<String,String> data = new HashMap<>();
        DataUtils.mapAddNoEmpty(data,params,new String[]{"deptId"});

        List<MajorEntity> major  = majorService.list(data);

        return R.ok().put("data", major);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{majorId}")
    @RequiresPermissions("easbaseinfo:major:info")
    public R info(@PathVariable("majorId") Integer majorId){
		MajorEntity major = majorService.getById(majorId);

        return R.ok().put("major", major);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("easbaseinfo:major:save")
    public R save(@RequestBody MajorEntity major){
		majorService.save(major);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("easbaseinfo:major:update")
    public R update(@RequestBody MajorEntity major){
		majorService.updateById(major);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("easbaseinfo:major:delete")
    public R delete(@RequestBody Integer[] majorIds){
		majorService.removeByIds(Arrays.asList(majorIds));

        return R.ok();
    }

}
